package com.muyu.controller;

import com.muyu.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: FileController
 * @Author: Zirun.Xin
 * @Date: 2025/4/24 下午4:42
 * @Version: 1.0
 * @Description: 用户控制层
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/api/v1/user")
public class UserController {

    /**
     * 用户业务层
     */
    private final UserService userService;

    /**
     * 上传用户头像
     *
     * @param file   文件
     * @param userId 用户标识
     * @return 响应结果集
     */
    @PostMapping(value = "/upload-img")
    public boolean uploadImg(MultipartFile file, Integer userId) {
        return userService.uploadImg(file, userId);
    }

    /**
     * 文件上传（支持批量）
     *
     * @param files 文件集
     * @param type  文件类型
     * @param dfId  主键标识
     * @return 是否上传成功
     */
    @PostMapping(value = "/upload-files")
    public boolean uploadFiles(@RequestParam(value = "files") MultipartFile[] files,
                               @RequestParam(value = "type") Integer type,
                               @RequestParam(value = "id") Integer dfId) {
        return userService.uploadFiles(files, type, dfId);
    }
}
